cmake_minimum_required(VERSION 3.10)
project(cuda_test_framework LANGUAGES CXX CUDA)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 对MSVC编译器设置 /utf-8 编码选项
if(MSVC)
    # 为C++代码添加/utf-8编译选项
    add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/utf-8>")
    
    # 可选的：禁用特定警告
    add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/wd4819>")  # 禁用UTF-8相关警告
endif()
if(FALSE)
    add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
    add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
endif()

# 添加头文件目录
include_directories(include)

# 分别处理C++和CUDA源文件
file(GLOB_RECURSE CPP_SOURCES "src/*.cpp")
file(GLOB_RECURSE CUDA_SOURCES "src/*.cu")

# 添加可执行文件，将CUDA文件单独列出
add_executable(cuda_test ${CPP_SOURCES} ${CUDA_SOURCES})

# 为MSVC编译器添加UTF-8编译选项
if(FALSE)
    # 为C++源文件设置UTF-8编码
    target_compile_options(cuda_test PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/utf-8>)
    # 为CUDA源文件通过-Xcompiler传递UTF-8选项给MSVC
    target_compile_options(cuda_test PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=/utf-8>)
endif()

# 确保CUDA文件被正确处理
set_property(SOURCE ${CUDA_SOURCES} PROPERTY LANGUAGE CUDA)

# 修复nvcc编译错误 - 禁用单独编译模式
set(CUDA_SEPARABLE_COMPILATION OFF)

# 链接CUDA库
target_link_libraries(cuda_test ${CUDA_LIBRARIES})

# 设置CUDA架构
set_property(TARGET cuda_test PROPERTY CUDA_ARCHITECTURES 80 86)

# 添加测试
enable_testing()
add_test(NAME cuda_device_info_test COMMAND cuda_test)